package com.zcmyth;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.google.common.collect.Lists;

public class Permutation {

  public static Set<List<Integer>> permute(List<Integer> list) {
    Set<List<Integer>> set = new HashSet<List<Integer>>();
    if (list.size() == 1) {
      set.add(Lists.newArrayList(list.get(0)));
    }
    for (int i = 0; i < list.size(); i++) {
      Integer temp = list.remove(0);
      Set<List<Integer>> result = permute(list);
      for (List<Integer> l : result) {
        l.add(0, temp);
        set.add(l);
      }
      list.add(temp);
    }
    return set;
  }

  public static void main(String[] args) {
    System.out.println(permute(Lists.newArrayList(1, 2, 3)));
  }
}
